home *** CD-ROM | disk | FTP | other *** search
/ Aminet 23 / Aminet 23 (1998)(GTI - Schatztruhe)[!][Feb 1998].iso / Aminet / text / edit / Smartindent.lha / Smartindent / Source / LibInit.c < prev    next >
C/C++ Source or Header  |  1997-12-14  |  4KB  |  147 lines

  1. /*(( "Kopf" */
  2. /* -----------------------------------------------------------------------------
  3.  
  4.    $Id: LibInit.c,v 1.4 1997/06/29 19:24:13 mshopf Exp mshopf $
  5.  
  6.    GoldED API client, ©1997 Matthias Hopf.
  7.    Compiled with SasC.
  8.  
  9.  
  10.    Library Inititalization
  11.  
  12.    ------------------------------------------------------------------------------
  13. */
  14.  
  15. /*)) */
  16. /*(( "Includes" */
  17.  
  18. #include <exec/types.h>
  19. #include <exec/memory.h>
  20. #include <exec/libraries.h>
  21. #include <exec/execbase.h>
  22. #include <exec/resident.h>
  23. #include <exec/initializers.h>
  24. #include <dos/dosextens.h>
  25.  
  26. #ifdef __MAXON__
  27. #include <clib/exec_protos.h>
  28. #else
  29. #include <proto/exec.h>
  30. #endif
  31. #include "compiler.h"
  32.  
  33. #include "smartindent.h"
  34. #include "util.h"
  35.  
  36.  
  37. /*)) */
  38. /*(( "Prototypes" */
  39.  
  40. ULONG __saveds __stdargs L_OpenLibs(void);
  41. void  __saveds __stdargs L_CloseLibs(void);
  42.  
  43. extern struct SmartindentBase *SmartindentBase;
  44.  
  45. extern ULONG InitTab[];
  46.  
  47. extern APTR EndResident;                /* below */
  48.  
  49. /*)) */
  50. /*(( "Data" */
  51.  
  52. struct DosLibrary    *DOSBase       = NULL;
  53. struct ExecBase      *SysBase       = NULL;
  54. struct IntuitionBase *IntuitionBase = NULL;
  55. struct GfxBase       *GfxBase       = NULL;
  56.  
  57. char __aligned SiLibName [] = LIBNAME;
  58. char __aligned SiLibID   [] = LIBID;
  59. char __aligned Copyright [] = "(C) 1997 Matthias Hopf";
  60.  
  61. struct Resident __aligned ROMTag =      /* do not change */
  62. {
  63.     RTC_MATCHWORD,
  64.     &ROMTag,
  65.     &EndResident,
  66.     RTF_AUTOINIT,
  67.     VERSION,
  68.     NT_LIBRARY,
  69.     0,
  70.     &SiLibName[0],
  71.     &SiLibID[0],
  72.     &InitTab[0]
  73. };
  74.  
  75. APTR EndResident;
  76.  
  77. struct MyDataInit                       /* do not change */
  78. {
  79.     UWORD ln_Type_Init;      UWORD ln_Type_Offset;      UWORD ln_Type_Content;
  80.     UBYTE ln_Name_Init;      UBYTE ln_Name_Offset;      ULONG ln_Name_Content;
  81.     UWORD lib_Flags_Init;    UWORD lib_Flags_Offset;    UWORD lib_Flags_Content;
  82.     UWORD lib_Version_Init;  UWORD lib_Version_Offset;  UWORD lib_Version_Content;
  83.     UWORD lib_Revision_Init; UWORD lib_Revision_Offset; UWORD lib_Revision_Content;
  84.     UBYTE lib_IdString_Init; UBYTE lib_IdString_Offset; ULONG lib_IdString_Content;
  85.     ULONG ENDMARK;
  86. } DataTab =
  87. {
  88.     INITBYTE(OFFSET(Node,         ln_Type),      NT_LIBRARY),
  89.     0x80, (UBYTE) OFFSET(Node,    ln_Name),      (ULONG) &SiLibName[0],
  90.     INITBYTE(OFFSET(Library,      lib_Flags),    LIBF_SUMUSED|LIBF_CHANGED),
  91.     INITWORD(OFFSET(Library,      lib_Version),  VERSION),
  92.     INITWORD(OFFSET(Library,      lib_Revision), REVISION),
  93.     0x80, (UBYTE) OFFSET(Library, lib_IdString), (ULONG) &SiLibID[0],
  94.     (ULONG) 0
  95. };
  96.  
  97.  
  98. /*)) */
  99.  
  100. /*(( "L_OpenLibs ()" */
  101.  
  102. /* Libraries not shareable between Processes or libraries messing
  103.    with RamLib (deadlock and crash) may not be opened here - open/close
  104.    these later locally and or maybe close them fromout L_CloseLibs()
  105.    when expunging !
  106. */
  107.  
  108. ULONG __saveds __stdargs L_OpenLibs(void)
  109. {
  110.     SysBase = (*((struct ExecBase **) 4));
  111.  
  112.     IntuitionBase = (struct IntuitionBase *) OpenLibrary("intuition.library", 37);
  113.     if(!IntuitionBase) return(FALSE);
  114.  
  115.     GfxBase = (struct GfxBase *) OpenLibrary("graphics.library", 37);
  116.     if(!GfxBase) return(FALSE);
  117.  
  118.     DOSBase = (struct DosLibrary *) OpenLibrary("dos.library", 37);
  119.     if(!DOSBase) return(FALSE);
  120.  
  121.     ExecVersion = SysBase->LibNode.lib_Version;
  122.     if (ExecVersion >= 39)
  123.     MemAllocSmallFlags = MEMF_CLEAR | MEMF_REVERSE;
  124.     else
  125.     MemAllocSmallFlags = MEMF_CLEAR; /* Pre-V39 exec.library has a bug with MEMF_REVERSE */
  126.  
  127.     return(TRUE);
  128. }
  129.  
  130.  
  131. /*)) */
  132. /*(( "L_CloseLibs ()" */
  133.  
  134. void __saveds __stdargs L_CloseLibs(void)
  135. {
  136.     if (DOSBase)       CloseLibrary ((struct Library *) DOSBase);
  137.     if (GfxBase)       CloseLibrary ((struct Library *) GfxBase);
  138.     if (IntuitionBase) CloseLibrary ((struct Library *) IntuitionBase);
  139.     DOSBase = NULL;
  140.     GfxBase = NULL;
  141.     IntuitionBase = NULL;
  142. }
  143.  
  144.  
  145. /*)) */
  146.  
  147.